﻿using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using WinTime.Services;
using WinTime.ViewModels;

namespace WinTime.Views;

// TODO: Set the URL for your privacy policy by updating SettingsPage_PrivacyTermsLink.NavigateUri in Resources.resw.
public sealed partial class SettingsPage : Page
{
    public SettingsViewModel ViewModel
    {
        get;
    }

    public SettingsPage()
    {
        ViewModel = App.GetService<SettingsViewModel>();
        InitializeComponent();
    }
    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var theme = (KeyValuePair<string, ElementTheme>)e.AddedItems[0];
        ViewModel.SwitchThemeCommand.Execute(theme.Value);
    }
    private void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var lang = (KeyValuePair<string, string>)e.AddedItems[0];
        if (ViewModel.SettingConfig.Language != lang.Value)
        {
            ViewModel.SettingConfig.Language = lang.Value;
            ViewModel.UpdateSettingConfigCommand.Execute(ViewModel.SettingConfig);
        }
    }

    private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
    {
        ViewModel.SettingConfig.IsAutoStartup = ((ToggleSwitch)sender).IsOn;
        ViewModel.UpdateSettingConfigCommand.Execute(ViewModel.SettingConfig);
    }
}
